package com.ruiysoft.controller.order;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruiysoft.controller.order.api.WechatorderApi;
import com.ruiysoft.controller.wx.api.service.WeChatApiService;
import com.ruiysoft.controller.wx.res.JsSignResponse;
import com.ruiysoft.entity.sys.SysShopPayPlatform;
import com.ruiysoft.entity.sys.SysShopPersonnel;
import com.ruiysoft.pub.core.Result;
import com.ruiysoft.pub.core.ResultGenerator;
import com.ruiysoft.service.order.IOrderCusPayService;
import com.ruiysoft.service.sys.clent.LoginContextUtil;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2018-11-27T16:57:35.761+08:00")

@RestController
public class WechatorderApiController implements WechatorderApi {

    private static final Logger log = LoggerFactory.getLogger(WechatorderApiController.class);

    private final ObjectMapper objectMapper;

    private final HttpServletRequest request;

    private final WeChatApiService weChatApiService;

    private final IOrderCusPayService orderCusPayService;

    @org.springframework.beans.factory.annotation.Autowired
    public WechatorderApiController(ObjectMapper objectMapper, HttpServletRequest request, WeChatApiService weChatApiService, IOrderCusPayService orderCusPayService) {
        this.objectMapper = objectMapper;
        this.request = request;
        this.weChatApiService = weChatApiService;
        this.orderCusPayService = orderCusPayService;
    }

    public Result<JsSignResponse> jssign(@ApiParam(value = "" ,required=true ) @PathVariable("orderNo") String orderNo) {
        SysShopPersonnel personnel =  LoginContextUtil.instance().getEntryUser().getPersonnel();
        Long shopId = LoginContextUtil.instance().getEntryMicroShop().getId();

        SysShopPayPlatform payPlatform = LoginContextUtil.instance().getShopPayPlatformByAppId(personnel.getAppId());

        return orderCusPayService.getOrGeneratePayTransaction(payPlatform, personnel.getId(), shopId , personnel.getOpenid(), orderNo);
    }

}
